import Vue from "vue"; // 引入Vue
import Vuex from "vuex"; // 引入vuex
Vue.use(Vuex); // Vue 注册Vuex
import createPersistedState from "vuex-persistedstate";

export default new Vuex.Store({
    state: {
      list: [
        { id: 100, name: "吃饭", isDone: true },
        { id: 201, name: "睡觉", isDone: false },
        { id: 103, name: "打豆豆", isDone: true },
        ],
    isSel: 'all'
    },
    mutations: {
        updateList(s, arr) { 
            s.list = arr
        },
        updateIsSel(s,isSel) { 
            s.isSel = isSel
            console.log(s.isSel);
        }
    },
    getters: {
        isAll(s) { 
          return  s.list.every(item=>item.isDone===true)
        }
    },
    plugins: [createPersistedState({
        key: "todoList", // 指定名称 默认vuex
        reducer({ list }) { return {list} }
      })]
}); // 初始化store,并抛出